
let glUtils = {

    bBlend:false,

    /**
     * https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/getError
     */
    checkGLError(gl){
        let ret = gl.getError();
        if(ret !== gl.NO_ERROR){
            switch (ret) {
                case gl.INVALID_ENUM:
                    console.error('An unacceptable value has been specified for an enumerated argument. The command is ignored and the error flag is set.');
                    break;
                case gl.INVALID_VALUE:
                    console.error('A numeric argument is out of range. The command is ignored and the error flag is set.');
                    break;
                case gl.INVALID_OPERATION:
                    console.error('The specified command is not allowed for the current state. The command is ignored and the error flag is set.');
                    break;
                case gl.INVALID_FRAMEBUFFER_OPERATION:
                    console.error('The currently bound framebuffer is not framebuffer complete when trying to render to or to read from it.');
                    break;
                case gl.OUT_OF_MEMORY:
                    console.error('Not enough memory is left to execute the command.');
                    break;
                case gl.CONTEXT_LOST_WEBGL:
                    console.error('If the WebGL context is lost, this error is returned on the first call to getError. Afterwards and until the context has been restored, it returns gl.NO_ERROR.');
                    break;
            }
        }
    },

    enableBlend(gl){
        if(!this.bBlend){
            this.bBlend = true;
            gl.enable(gl.BLEND);
            gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA);
        }
    },

    disableBlend(gl){
        if(this.bBlend){
            this.bBlend = false;
            gl.disable(gl.BLEND);
        }
    }

};

module.exports = glUtils;
